package com.demarc.pesquisas.web.converter;

import javax.faces.convert.FacesConverter;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;

import com.demarc.pesquisas.negocio.util.DateUtils;

@FacesConverter(value = "LocalDateConverter", forClass = LocalDate.class)
public class LocalDateConverter extends AbstractJodaTimeConverter {

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Object getAsObject(DateTime dateTime) {
		LocalDate date = null;

		if (dateTime != null) {
			date = dateTime.toLocalDate();
		}
		return date;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected String getAsString(Object object) {
		String value = null;

		if (object instanceof LocalDate) {
			value = ((LocalDate) object).toString(getPattern());
		}
		return value;
	}

	@Override
	protected String getPattern() {
		return DateUtils.getPadraoData();
	}
}
